const util = require('../../utils/util.js'),
  regeneratorRuntime = require('../../utils/runtime.js'),
  app = getApp(),
  HttpAjax = getApp().getHttpData;
Page({
  data: {
    cardnum: '********',
    validval: '',
    btnshow: !1
  },
  onLoad: function() {
    let a = this,
      b = app.globalData.cardid;
    10 < b.replace(/ /g, '').length ? this.setData({
      cardnum: '********'.padStart(b.replace(/ /g, '').length, '*')
    }) : this.setData({
      cardnum: '*'.padStart(10, '*')
    })
  },
  onShow() {},
  SetIn() {
    let b = this.data.validval,
      c = this;
    if ('' == b) return void wx.showToast({
      title: '\u8BF7\u8F93\u5165\u65B0\u5361\u53F7',
      icon: 'none',
      duration: 2e3
    });
    let d;
    if (18 == b.length) {
      if (d = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, !1 === d.test(b)) return void wx.showToast({
        title: '\u53EA\u80FD\u8F93\u5165\u6570\u5B57\u6216\u8EAB\u4EFD\u8BC1\u53F7\u7801',
        icon: 'none',
        duration: 2e3
      });
    } else if (d = /^[0-9]*$/, !1 === d.test(b)) return void wx.showToast({
      title: '\u53EA\u80FD\u8F93\u5165\u6570\u5B57\u6216\u8EAB\u4EFD\u8BC1\u53F7\u7801',
      icon: 'none',
      duration: 2e3
    });
    (function() {
      c.setData({
        btnshow: !0
      }), HttpAjax(app.globalData.url + '/MicroApp/CardData', {
        Card: b
      }, 'post', app.globalData.headerCookie).then(f => {
        if (c.setData({
            btnshow: !1
          }), '1' == f.data.result) {
          wx.showToast({
            title: '\u8BBE\u7F6E\u6210\u529F',
            icon: 'none',
            duration: 2e3
          }), app.globalData.cardid = b, app.globalData.qrcodeRefres = !0;
          let g = app.globalData.cardid.replace(/ /g, '');
          10 < g.length ? c.setData({
            cardnum: '********'.padStart(g.length, '*')
          }) : c.setData({
            cardnum: '*'.padStart(10, '*')
          })
        } else wx.showToast({
          title: f.data.Message,
          icon: 'none',
          duration: 2e3
        })
      }).catch(() => {
        wx.showToast({
          title: '\u8BBE\u7F6E\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5',
          icon: 'none',
          duration: 2e3
        }), c.setData({
          btnshow: !1
        })
      })
    })()
  },
  getAuthCode(a) {
    this.setData({
      validval: a.detail.value
    })
  },
  getnfc() {
    wx.getHCEState({
      success(a) {
        wx.showToast({
          title: 'getHCEState' + a.errCode,
          duration: 2e3
        });
        const b = new ArrayBuffer(1),
          c = new DataView(b);
        c.setUint8(0, 0), wx.startHCE({
          aid_list: ['F223344556'],
          success: function() {
            wx.showToast({
              title: 'startHCE',
              duration: 2e3
            }), wx.onHCEMessage(function(f) {
              wx.showToast({
                title: 'onHCEMessage',
                duration: 2e3
              }), 1 === f.messageType && wx.sendHCEMessage({
                data: b,
                success: () => {},
                fail: () => {}
              })
            })
          },
          fail() {}
        })
      },
      fail(a) {
        wx.showToast({
          title: a,
          duration: 2e3
        })
      }
    })
  },
  stopNFC() {
    wx.stopHCE({
      success: function(a) {
        console.log('stopHCE'), console.log(a.errMsg)
      },
      fail: a => {
        console.log(a)
      }
    })
  },
  showId() {
    let a = app.globalData.cardid.replace(/ /g, '');
    10 < a.length ? this.setData({
      cardnum: a
    }) : this.setData({
      cardnum: (a + '').padStart(10, 0)
    })
  },
  unshowId() {
    let a = app.globalData.cardid.replace(/ /g, '');
    10 < a.length ? this.setData({
      cardnum: '********'.padStart(a.length, '*')
    }) : this.setData({
      cardnum: '*'.padStart(10, '*')
    })
  }
});